package com.ms.pda.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.ms.pda.model.table.*

@Database(
    entities = [StorageOutDO::class],
    version = 1
)
abstract class AppDataBase() : RoomDatabase() {

    abstract fun storageDao(): StorageDAO

    companion object {
        @Volatile
        private var INSTANCE: AppDataBase? = null

        @Synchronized
        fun getDataBase(context: Context): AppDataBase {
            return if (null == INSTANCE) {
                val instance =
                    Room.databaseBuilder(
                        context.applicationContext,
                        AppDataBase::class.java,
                        "ms_pda"
                    )
                        .fallbackToDestructiveMigration()
                        .build()
                INSTANCE = instance
                instance
            } else {
                val instance = INSTANCE
                instance!!
            }
        }

    }
}